package com.lcq.demo.controller;

import com.lcq.demo.entity.po.ScheduleTask;
import com.lcq.demo.service.ScheduleTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/tasks")
public class ScheduleTaskController {


    @Autowired
    private ScheduleTaskService scheduleTaskService;

    @GetMapping
    public List<ScheduleTask> getTasks() {
        return scheduleTaskService.getTasks();
    }

    @PostMapping
    public ScheduleTask addTask(@RequestBody ScheduleTask task) {
        scheduleTaskService.addTask(task);
        return task;
    }

    @PutMapping("/{id}")
    public ScheduleTask updateTask(@PathVariable Long id, @RequestBody ScheduleTask task) {
        scheduleTaskService.updateTask(id, task);
        return task;
    }

    @DeleteMapping("/{id}")
    public void deleteTask(@PathVariable Long id) {
        scheduleTaskService.deleteTask(id);
    }

    @PostMapping("/{id}/start-once")
    public void startTaskOnce(@PathVariable Long id) {
        scheduleTaskService.startTaskOnce(id);
    }

    @PostMapping("/{id}/stop")
    public void stopTask(@PathVariable Long id) {
        scheduleTaskService.stopTask(id);
    }

    @PostMapping("/{id}/start")
    public void startTask(@PathVariable Long id) {
        scheduleTaskService.startTask(id);
    }

}
